'use strict' import { QueryTable, TranslateToObject, Query } from '@feedyou/utils' import { saveBotComment, COMMENTS_TABLE } from '../../storageService' import { WrongInputError, NotFoundError, InternalError } from '../../../../utils/customErrors' import { Request } from 'express' /** * Operations on /bots/{id}/comments/{commentId} */ export default { /**Updates comment */ async patchComment(req: Request) { const comment = req.body if (comment) { try { await saveBotComment(req.params.id, comment) const entries = await TranslateToObject( await QueryTable( COMMENTS_TABLE, Query().where('RowKey eq ?', req.params.commentId || comment.id) ) ) if (entries && entries.length > 0) { return { comment: entries[0] } } else { throw new NotFoundError('No comments in table had been found') } } catch (error) { console.error("CAN'T INSERT COMMENT", error) throw new InternalError(error) } } else { throw new WrongInputError('body does not contain element "comment"') } } }